package com.lv.LvTourismOrder.dao;
import com.aqgj.util.BaseDaoImpl;
import com.lv.LvTourismOrder.bean.LvTourismOrder;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @ClassName LvTourismOrderDao
 * @JDK 1.5
 * @author
 * @date
 */
@Repository("LvTourismOrderDao")
public class LvTourismOrderDao extends BaseDaoImpl<LvTourismOrder> {
    /**
     * 修改
     * @param lvTourismOrder 实体bean
     * @return 0.失败，1.成功
     */
    public String update(LvTourismOrder lvTourismOrder) {
        this.getHibernateTemplate().saveOrUpdate(lvTourismOrder);
        if (lvTourismOrder.getId() != null) {
            return "1";
        }
        return "0";
    }

    /**
     * 搜索旅游订单信息
     * @param sql sql语句
     * @return
     */
    public List<LvTourismOrder> search(String sql) {
        List<LvTourismOrder> list = this.currentSession().createNativeQuery(sql,LvTourismOrder.class).getResultList();
        return list;
    }

    /**
     * 获取订单详情
     * @param orderId 订单id
     * @return
     */
    public List<Object[]> getOrderDetail(String orderId) {
        String sql="SELECT com.full_name,concat_ws('-',z.start_site_name,z.terminal_site_name) name,z.order_number,z.`status`,z.order_balance,z.pay_balance,z.refund_balance,z.contact_name,z.contact_phone,z.`type`,z.pay_type,z.order_time,z.pay_time,z.finish_time,z.refund_time,z.refund_reason,GROUP_CONCAT(CONCAT_WS(" +
                "',',ti.passenger_name," +
                "ifnull(ti.passenger_birthday,'')," +
                "ti.passenger_type," +
                "ti.passenger_card_number," +
                "ti.passenger_card_type) SEPARATOR ';') passenger," +
                "z.id " +
                "FROM lv_tourism_order z " +
                "INNER JOIN ztc_transport com ON z.fk_transport_id=com.id " +
                "INNER JOIN lv_tourism_order_customer ti ON z.id=ti.fk_tourism_order_id where z.id='"+orderId+"'";
        return this.createSQLQuery(sql).getResultList();
    }
}